<%@ page import="com.cgah.Constants; com.cgah.Customer" %>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
    <meta name="layout" content="main"/>
    <g:set var="entityName" value="${message(code: 'customer.label', default: 'Customer')}"/>
    <title><g:message code="default.show.label" args="[entityName]"/></title>
</head>
<body>
<div class="nav"><span class="spacer"></span>
%{--<span class="menuButton"><a class="home" href="${createLink(uri: '/')}"><g:message code="default.home.label"/></a></span>--}%

    <sec:ifAllGranted roles="${Constants.ROLE_ADMIN}">
        <span class="menuButton"><g:link class="list" action="list"><g:message code="default.list.label" args="[entityName]"/></g:link></span>
        <span class="menuButton"><g:link class="create" action="create"><g:message code="default.new.label" args="[entityName]"/></g:link></span>
    </sec:ifAllGranted>
    <sec:ifNotGranted roles="${Constants.ROLE_ADMIN}">
        <span class="spacer"></span>
    </sec:ifNotGranted>

</div>
<div class="body">

    <sec:ifAllGranted roles="${Constants.ROLE_ADMIN}">
        <h1><g:message code="default.show.label" args="[entityName]"/></h1>
    </sec:ifAllGranted>
    <sec:ifNotGranted roles="${Constants.ROLE_ADMIN}">
        <h1>My Profile</h1>
    </sec:ifNotGranted>

    <g:if test="${flash.message}">
        <div class="message">${flash.message}</div>
    </g:if>
    <div class="dialog">
        <table>
            <tbody>

            <tr class="prop">
                <td valign="top" class="name"><g:message code="customer.id.label" default="Id"/></td>

                <td valign="top" class="value">${fieldValue(bean: customerInstance, field: "id")}</td>

            </tr>

            <tr class="prop">
                <td valign="top" class="name"><g:message code="customer.emailAddress.label" default="Email Address"/></td>

                <td valign="top" class="value">
                    <input type="text" name="oldEmailAddress" id="oldEmailAddress" value="${fieldValue(bean: customerInstance, field: "emailAddress")}">
                </td>

            </tr>

            <tr class="prop">
                <td valign="top" class="name"><g:message code="customer.password.label" default="Password"/></td>

                <td valign="top" class="value">
                    <input type="text" name="oldPassword" id="oldPassword" value="${fieldValue(bean: customerInstance, field: "password")}">

                </td>

            </tr>

            <tr class="prop">
                <td valign="top" class="name"><g:message code="customer.createdDate.label" default="Created Date"/></td>

                <td valign="top" class="value"><g:formatDate date="${customerInstance?.createdDate}"/></td>

            </tr>

            <tr class="prop">
                <td valign="top" class="name"><g:message code="customer.listings.label" default="Listings"/></td>

                <td valign="top" style="text-align: left;" class="value">
                    <ul>
                        <g:each in="${customerInstance?.listings}" var="l">
                            <li><g:link controller="listing" action="show" id="${l.id}">${l?.encodeAsHTML()}</g:link></li>
                        </g:each>
                    </ul>
                </td>

            </tr>

            <tr class="prop">
                <td valign="top" class="name"><g:message code="customer.winnings.label" default="Winnings"/></td>

                <td valign="top" style="text-align: left;" class="value">
                    <ul>
                        <g:each in="${customerInstance?.winnings}" var="w">
                            <li><g:link controller="listing" action="show" id="${w.id}">${w?.encodeAsHTML()}</g:link></li>
                        </g:each>
                    </ul>
                </td>

            </tr>

            <tr class="prop">
                <td valign="top" class="name"><g:message code="customer.bids.label" default="Bids"/></td>

                <td valign="top" style="text-align: left;" class="value">
                    <ul>
                        <g:each in="${customerInstance?.bids}" var="b">
                            <li><g:link controller="bid" action="show" id="${b.id}">${b?.encodeAsHTML()}</g:link></li>
                        </g:each>
                    </ul>
                </td>

            </tr>

            </tbody>
        </table>
    </div>
    <div class="buttons">
        <g:form onsubmit="return updateValues()" action="edit" controller="user">
            <g:hiddenField name="id" value="${customerInstance?.id}"/>
            <g:hiddenField name="password" value="${customerInstance?.password}"/>
            <g:hiddenField name="email" value="${customerInstance?.emailAddress}"/>
            <span class="button">
                <g:actionSubmit class="save" action="edit" style="border-color:ActiveBorder; border-style:solid; border-width:2px;"
                        value="${message(code: 'default.button.update.label', default: 'Update')}"/>
            </span>
        </g:form>
    </div>
</div>
<script type="text/javascript">
    <!--
    function updateValues() {

        $("#password").val($("#oldPassword").val());
        $("#emailAddress").val($("#oldEmailAddress").val());
        return true;
    }
    // -->
</script>
</body>
</html>
